<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\LinkPager;
$this->title = '问答列表';

?>
<link href="/static/css/public-same.css" rel="stylesheet">
<link href="/static/css/question.css" rel="stylesheet">

<!-- block-nav-banner -->
<div class="block-nav-banner">
<div class="container">
<ul class="list-inline zy-list-inline">
<li class="active"><a href="<?= Url::to(['questions/index'])?>">问答</a></li>
<li><a href="<?= Url::to(['questions/release'])?>">发布问题</a></li>
</ul>
</div>
</div>




<!-- main-area -->
<div class="main-area QA-area" style=" background: #f5f5f5;">
<div class="container">
<div class="column-layout">
<!-- main-area-left start  -->
<div class="column-col main-area-left">
<div class="main-area-leftin">
<div class="ibox">
<div class="ibox-in">
<div class="ibox-head row">
    <div class="col-left">
            <ul class="list-inline zy-list-inline">
                <li class="active"><a href="<?= Url::to(['questions/index'])?>?action=new">最新</a></li>
                <li><a href="<?= Url::to(['questions/index'])?>?action=hot">最热</a></li>
                <li><a href="<?= Url::to(['questions/waiting'])?>?action=wait">等待回复</a></li>
                <li><a href="<?= Url::to(['questions/course'])?>?action=course">课程问答</a></li>
            </ul> 
    </div>
    
</div>

<!-- 活动列表  -->
<div class="ibox-body">
    <div class="QA-list">
    <?php 
      if(empty($name)){
            echo "抱歉！内容暂时不存在";
        }
       foreach($name as $key=>$val){?>
        <!-- item  -->
        <div class="item">
            <div class="col-left">
                <div class="col-in">
                    <div class="u-photo-box">
                        <a href="javascript:void(0);" target="_blank" id="40843" class="u-photo u-photo-btn">
                            <img src="http://files.bwphp.com/file/image/show/50/50?path=<?= Html::encode($val['user_thumb'])?>" alt="" height="50" width="50">
                        </a>
                        
                        <i class="ico ico-umark-2"></i>
                        
                    </div>
                    <span class="u-name"><?= Html::encode($val['user_name']);?></span>
                    
                </div>
            </div>
            <div class="col-right">
                <div class="col-in item-r-main">
                    <h3>
                    <?php if(!empty($user)){?>
                        <a href="<?= Url::to(['questions/details'])?>?ques_id=<?php echo $val['ques_id']?>" target="_blank" class="count" name="<?= Html::encode($val['ques_id']) ?>">
                            
                            <?= Html::encode($val['ques_name'])?>
                        </a>
                    <?php }else{?>
                        <a href="javascript:void(0)" class="count submit-reply" name="<?= Html::encode($val['ques_id']) ?>">
                            
                            <?= Html::encode($val['ques_name'])?>
                        </a>
                    <?php }?>    
                    </h3>
                    <div class="item-r-A">
                        
                        <span class="tips">[最佳答案]</span>
                        <?php if(!empty($user)){?>
                        <a href="<?= Url::to(['questions/details'])?>?ques_id=<?php echo $val['ques_id']?>" class="count" name="<?= Html::encode($val['ques_id']) ?>">
                        <?php 
                            foreach ($answer as $kk => $vo)
                            {
                                if($vo['ques_id']==$val['ques_id'])
                                {  
                                    echo $vo['answer_content']; 
                                }
                            }
                        ?>
                        </a>
                    <?php }else{?>
                        <a href="javascript:void(0)" class="count submit-reply" name="<?= Html::encode($val['ques_id']) ?>">
                        <?php 
                            foreach ($answer as $kk => $vo)
                            {
                                if($vo['ques_id']==$val['ques_id'])
                                {  
                                    echo $vo['answer_content']; 
                                }
                            }
                        ?>
                        </a>
                    <?php }?>    
                    </div>
                    <div class="hot-tag-group">
                        
                        <a href="javascript:void(0);" class="hot-tag"><?= Html::encode($val['queslabel_name'])?></a>  
                    </div>
                    <div class="item-r-foot ask-item-r-foot">
                        <div class="col-left" style="width: 26% !important;">
                            
                            <span class="datetime">
                    <?php  
                        $dur = time()-$val['ques_addtime'];
                        /*暂时没想到怎么做、先做成这样的*/
                        if($dur<60){
                            echo $dur."秒前";
                        }else{
                            if($dur<3600){
                                echo floor($dur/60)."分钟前";
                            }else{
                                if($dur<86400){
                                    echo floor($dur/3600)."小时前";
                                }else{
                                    if($dur<604800){
                                        echo floor($dur/86400)."天前";
                                    }else{
                                        if($dur<2592000){
                                            echo floor($dur/604800)."周前";
                                        }else{
                                            if($dur<31104000){
                                                echo floor($dur/2592000)."月前";
                                            }else{
                                                if($dur>31104000){
                                                    echo floor($dur/31104000)."年前";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        echo $year;
                    ?>
                            </span>
                        
                        </div>

                    <?php if(!empty($val['course_name'])){?>
                    <a href=''>来源:<?= Html::encode($val['course_name'])?></a>
                    <?php }?>
                        <div class="col-right">
                            <span class="i-item">
                                <a href="javascript:void(0);" >回答(<?= Html::encode($val['ques_answersum'])?>)</a>
                            </span>
                            <span class="i-item">
                                <a href="javascript:void(0);" >浏览(<?= Html::encode($val['ques_viewsum'])?>)</a>
                            </span>
                            <!-- <span class="i-item fun-btn u-share" style="position: relative;"
                                  id="share-9912"
                                  is_lesson="0"  >
                                <a href="javascript:void(0);">分享</a>
                              <div class="share-ibox" style="display: none;     position: absolute;     bottom: 100%;     margin-bottom: 5px;     left: -212%;     padding: 5px 8px;     border: 1px solid #bcd2ce;     border-radius: 5px;     background: rgba(255,255,255,0.75);width: 138px;">
                                <div class="jiathis_style">
                                  <a class="jiathis_button_qzone"></a>
                                  <a class="jiathis_button_tsina"></a>
                                  <a class="jiathis_button_tqq"></a>
                                  <a class="jiathis_button_weixin"></a>
                                  <a class="jiathis_button_renren"></a>
                                </div>
                              </div>
                            </span>
                            <span class="i-item fun-btn
                            praise-btn
                            "
                            id="praise-9912
                                ">
                                <a href="javascript:void(0);"><i class="ico ico-good"></i></a>
                                <span class="ico-label-text">0</span>
                            </span> -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    <?php }?>   
        
        
    </div>
    <!-- 翻页  -->
<div align="center">
        <?php echo LinkPager::widget([
            'pagination' =>$pages,
            'prevPageLabel'=>'上一页',
            'nextPageLabel'=>'下一页',
            
        ]);?>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- main-area-left end  -->
<!-- main-area-right start  -->
<?php echo $this->render('common')?>
<!-- main-area-right end  -->
</div>
</div>
</div>
</div>
<script>
    /*调用登录*/
    $(".submit-reply").click(function(){
        login_popup()
    })

    $(".count").click(function(){
        var ques_id = $(this).attr("name");
        $.ajax({
                type: "POST",
                url: "<?= Url::to(['questions/count'])?>",
                data: "ques_id="+ques_id,
                success: function(){
                    
                }
            })
    })
</script>